package cn.stylefeng.guns.modular.jobTask.controller;

import cn.stylefeng.guns.modular.jobTask.entity.JobTask;
import cn.stylefeng.guns.modular.jobTask.pojo.request.JobTaskRequest;
import cn.stylefeng.guns.modular.jobTask.pojo.result.JobTaskNodeResult;
import cn.stylefeng.guns.modular.jobTask.service.JobTaskService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 任务表控制器
 *
 * @author LiZh
 * @date 2024.07.08
 */
@RestController
@CrossOrigin
@ApiResource(name = "任务表")
public class JobTaskController {

    @Resource
    private JobTaskService jobTaskService;

    /**
     * 添加
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @PostResource(name = "添加", path = "/jobTask/add", requiredLogin = false, requiredPermission = false)
    public ResponseData<JobTask> add(@RequestBody @Validated(JobTaskRequest.add.class) JobTaskRequest jobTaskRequest) {
        jobTaskService.add(jobTaskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @PostResource(name = "删除", path = "/jobTask/delete", requiredLogin = false, requiredPermission = false)
    public ResponseData<?> delete(@RequestBody @Validated(JobTaskRequest.delete.class) JobTaskRequest jobTaskRequest) {
        jobTaskService.del(jobTaskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @PostResource(name = "编辑", path = "/jobTask/edit", requiredLogin = false, requiredPermission = false)
    public ResponseData<?> edit(@RequestBody @Validated(JobTaskRequest.edit.class) JobTaskRequest jobTaskRequest) {
        jobTaskService.edit(jobTaskRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @GetResource(name = "查看详情", path = "/jobTask/detail", requiredLogin = false, requiredPermission = false)
    public ResponseData<JobTask> detail(@Validated(JobTaskRequest.detail.class) JobTaskRequest jobTaskRequest) {
        return new SuccessResponseData<>(jobTaskService.detail(jobTaskRequest));
    }

    /**
     * 获取列表
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @GetResource(name = "获取列表", path = "/jobTask/list", requiredLogin = false, requiredPermission = false)
    public ResponseData<List<JobTask>> list(JobTaskRequest jobTaskRequest) {
        return new SuccessResponseData<>(jobTaskService.findList(jobTaskRequest));
    }

    /**
     * 获取树
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @GetResource(name = "获取树", path = "/jobTask/tree", requiredLogin = false, requiredPermission = false)
    public ResponseData<List<JobTaskNodeResult>> tree(JobTaskRequest jobTaskRequest) {
        return new SuccessResponseData<>(jobTaskService.tree(jobTaskRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author LiZh
     * @date 2024.07.08
     */
    @GetResource(name = "分页查询", path = "/jobTask/page", requiredLogin = false, requiredPermission = false)
    public ResponseData<PageResult<JobTask>> page(JobTaskRequest jobTaskRequest) {
        return new SuccessResponseData<>(jobTaskService.findPage(jobTaskRequest));
    }

}
